from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# 打开浏览器
driver1 = webdriver.Chrome()
# 最大化
driver1.maximize_window()
# 请求qq邮箱网址
driver1.get('https://mail.qq.com')
# 切换frame页面
driver1.switch_to.frame('login_frame')
time.sleep(2)
# 找到信息框,输入信息
driver1.find_element(By.ID, 'u').send_keys('123456')
driver1.find_element(By.ID, 'p').send_keys('123456')
# 点击登录按钮
driver1.find_element(By.ID, 'login_button').click()
# 等待10s手动滑动图片验证
time.sleep(10)
# 获取所有cookie
code = driver1.get_cookies()
# 新打开一个浏览器
driver = webdriver.Chrome()
# 最大化
driver.maximize_window()
# 请求qq邮箱网址
driver.get('https://mail.qq.com')
# 删除所有的cookie
driver.delete_all_cookies()
# 依次添加cookie
for i in code:
    driver.add_cookie(i)
# 刷新网页
time.sleep(2)
driver.refresh()
# 找到写信按钮,点击
time.sleep(2)
driver.find_element(By.ID, 'composebtn').click()
# 切换frame页面
driver.switch_to.frame('mainFrame')
# 找到收件人,输入信息
time.sleep(2)
s1 = driver.find_element(By.XPATH, '//*[@id="toAreaCtrl"]/div[2]/input')
s1.send_keys('1023646734@qq.com')
# 找到主题框,输入信息
time.sleep(2)
z1 = driver.find_element(By.ID, 'subject')
z1.send_keys('111')
# 切换frame页面
time.sleep(2)
f1 = driver.find_element(By.CLASS_NAME, 'qmEditorIfrmEditArea')
driver.switch_to.frame(f1)
# 找到正文页面
time.sleep(2)
b1 = driver.find_element(By.XPATH, '/html/body')
b1.send_keys('111')
# 切换回父页面
time.sleep(2)
driver.switch_to.parent_frame()
# 找到发送按钮点击
time.sleep(2)
send = driver.find_element(By.LINK_TEXT, '发送')
send.click()
# 关闭两个浏览器
time.sleep(2)
driver.quit()
driver1.quit()